package com.lyzx.newboot2.day01.helloworld.model;

import java.math.BigDecimal;

public class Mango {
    private final String name="芒果";
    private BigDecimal count;   //购买数量(斤数)
    private BigDecimal price;   //价格
    private BigDecimal disCount; //折扣
    private BigDecimal totalMoney;  //总价

    public String getName() {
        return name;
    }

    public Mango(BigDecimal count, BigDecimal price, BigDecimal disCount) {
        if(count.compareTo(new BigDecimal("0")) < 0 ){
            throw new IllegalArgumentException("购买"+name+"的斤数不能小于0");
        }

        this.count = count;

        this.price = price;

        if(null == disCount){
            disCount= new BigDecimal(1);
        }
        this.disCount = disCount;
    }

    public BigDecimal getTotalMoney(){
        BigDecimal r1 = price.multiply(new BigDecimal(String.valueOf(this.count)));
        totalMoney = r1.multiply(new BigDecimal(String.valueOf(this.disCount)));
        return totalMoney;
    }

    public String say(){
        return "购买"+name+"["+count+"]斤 单价["+price+"]元 共花费["+getTotalMoney()+"]元";
    }
}
